import 'package:animal/utils/screen_util.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'color.dart';
import 'font.dart';

class MyAppBar {
  ///导航栏 appBar
  static Widget defaultAppBar({
    bool showLine = true,
    bool showBack = true,
    String? barTitle,
    double marginLeft = 0,
    double marginRight = 0,
    double marginButton = 0,
    double marginTop = 0,
    Alignment? alignment = Alignment.center,
    Color? textColor,
    Widget? rightWidget,
    Widget? loading,
    Widget? title,
    Color? bgColor = Colors.transparent,
  }) {
    return Container(
      height: ScreenUtil().L(50),
      width: double.infinity,
      margin: EdgeInsets.only(top: ScreenUtil.statusBarHeight),
      decoration:
      BoxDecoration(color: bgColor, border: Border(bottom: BorderSide(width: ScreenUtil().L(1), color: showLine ? Colors.black12 : Colors.transparent))),
      child: Stack(
        children: <Widget>[
        Visibility(
        visible: showBack,
        child: loading ?? barLeftBack(),
      ),
      title??Container(),
          Visibility(
            visible:barTitle!=null,
            child: Container(
              alignment: alignment,
              margin: EdgeInsets.only(left: marginLeft, top: marginTop, bottom: marginButton, right: marginRight),
              width: double.infinity,
              child: Text(
                barTitle!,
                style: KFontConstant.myTextStyle(size: 20, color: textColor??Colors.black, bold: true),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
      Align(alignment: Alignment.centerRight, child: Visibility(child: rightWidget ?? Container(), visible: rightWidget != null))
      ],
    ),);
  }

  ///appbar 右边text
  static Widget barRightText({String? title, Function? onTap}) {
    return InkWell(
      child: Container(
          padding: EdgeInsets.only(right: ScreenUtil().L(30), left: ScreenUtil().L(30), top: ScreenUtil().L(20), bottom: ScreenUtil().L(20)),
          child: Text(
            "" + title!,
            style: KFontConstant.myTextStyle(size: KFontConstant.defaultTextSize, color: KColorConstant.theme, bold: true),
          )),
      onTap: () {
        onTap!;
      },
    );
  }

  ///左边返回按钮——默认状态
  static Widget barLeftBack() {
    return InkWell(
      onTap: () => Get.back(),
      child: Container(
        height: ScreenUtil().L(100),
        width: ScreenUtil().L(100),
        padding: EdgeInsets.all(ScreenUtil().L(30)),
        child: Image.asset("icons/icon_back.png", color: Colors.black, width: ScreenUtil().L(25), fit: BoxFit.cover),
      ),
    );
  }
}
